using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;


namespace Zephyris_Space_Mercs
{
    class AboutMenu
    {
        int timeCounter = 0;

        List<ClickableRegion> clickableRegions = new List<ClickableRegion>();

        UI interfaceUI;
        SpriteFont uiFont;
        Texture2D uiBackground;
        Texture2D uiButton;

        GraphicsDevice device;

        public void Init(SpriteBatch spriteBatch, SpriteBatch uiBatch, GraphicsDevice device)
        {
            interfaceUI = new UI(spriteBatch, uiBatch);
            this.device = device;
        }

        public void LoadContent(Texture2D uiBackground, Texture2D uiButton, SpriteFont uiFont)
        {
            this.uiBackground = uiBackground;
            this.uiButton = uiButton;
            this.uiFont = uiFont;
        }

        public void DrawScreen()
        {
            timeCounter++;
            if (timeCounter > Constants.timeCounterVal)
                timeCounter = 0;

            interfaceUI.drawScreen(uiBackground);
            clickableRegions.Clear();

            Vector2 topleft = new Vector2(0, 0);
            Vector2 bottomright = new Vector2(0, 0);

            topleft = new Vector2((device.Viewport.Width / 2) - (uiButton.Width / 2), (device.Viewport.Height / 2));
            bottomright = new Vector2(topleft.X + this.uiButton.Width, topleft.Y + this.uiButton.Height);
            interfaceUI.drawButton(uiButton, topleft, uiFont, " Exit");
            AddClickable(topleft, bottomright);

            Vector2 textOffset = new Vector2(0, 0);

            textOffset = new Vector2(20, 20);
            interfaceUI.drawText(textOffset, uiFont, Constants.version);
            AddClickable(textOffset, new Vector2(device.Viewport.Width, textOffset.Y + 40));
        }

        public void AddClickable(Vector2 topleftCorner, Vector2 bottomrightCorner)
        {
            ClickableRegion clickableRegion = new ClickableRegion();
            clickableRegion.TopLeftCorner = topleftCorner;
            clickableRegion.BottomRightCorner = bottomrightCorner;
            clickableRegions.Add(clickableRegion);
        }

        public UIPages.UIPage CheckClick(Vector2 clickedRegion)
        {
            if (timeCounter > Constants.timeCounterVal / 2)
            {
                for (int i = 0; i < clickableRegions.Count; i++)
                {
                    switch (i)
                    {
                        case 0:
                            if ((clickedRegion.X > clickableRegions[0].TopLeftCorner.X) && (clickedRegion.X < clickableRegions[0].BottomRightCorner.X)
                                &&
                                (clickedRegion.Y > clickableRegions[0].TopLeftCorner.Y) && (clickedRegion.Y < clickableRegions[0].BottomRightCorner.Y))
                            {
                                timeCounter = 0;
                                return UIPages.UIPage.MainMenu;
                            }
                            break;

                    }
                }
            }
            return UIPages.UIPage.AboutMenu;
        }
    }
}
